import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router"
import Layout from "@/layouts/index.vue"
const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    component: () => import("@/layouts/index.vue"),
    redirect: "/dashboard",
    children: [
      {
        name: "Dashboard",
        path: "dashboard",
        meta: {
          title: "控制台",
          icon: "ep:alarm-clock",
          affix: true
          // noCache: true
        },
        component: () => import("@/views/Dashboard/index.vue")
      }
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/Login/index.vue"),
    meta: { hidden: true }
  },
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/Redirect/index.vue")
      }
    ]
  }
]

const asyncRoutes: RouteRecordRaw[] = [
  {
    path: "/feature",
    component: Layout,
    redirect: "/feature/index",
    children: [
      {
        name: "Feature",
        path: "index",
        meta: { title: "功能", icon: "ep:opportunity" },
        component: () => import("@/views/Feature/index.vue")
      }
    ]
  },
  {
    path: "/systemSetting",
    component: Layout,
    redirect: "/systemSetting/accountManagement",
    meta: {
      title: "系统设置",
      icon: "ep:setting",
      alwaysShow: true,
      breadcrumb: false
    },
    children: [
      // 账号管理
      {
        name: "AccountManagement",
        path: "accountManagement",
        meta: { title: "账号管理", icon: "ep:user", affix: true },
        component: () => import("@/views/AccountManagement/index.vue")
      },
      {
        name: "UserManagement",
        path: "userManagement",
        meta: { title: "用户管理", icon: "ep:user" },
        component: () => import("@/views/UserManagement/index.vue")
      },
      // 角色管理
      {
        name: "RoleManagement",
        path: "roleManagement",
        meta: { title: "角色管理", icon: "ep:user" },
        component: () => import("@/views/RoleManagement/index.vue")
      }
    ]
  },
  {
    path: "/richTextEditor",
    component: Layout,
    redirect: "/richTextEditor/wangEditor",
    children: [
      {
        name: "WangEditor",
        path: "wangEditor",
        meta: { title: "富文本编辑器", icon: "ep:document" },
        component: () => import("@/views/WangEditor/index.vue")
      }
    ]
  },
  {
    path: "/link",
    component: Layout,
    children: [
      {
        name: "nestjs 官网",
        path: "http://www.baidu.com?q=nestjs",
        redirect: "/",
        meta: { title: "nestjs 官网", icon: "ep:link" }
      }
    ]
  }
]

export const routes = [...constantRoutes, ...asyncRoutes]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

export default router
